<template>
	<view class="main">
		<u-navbar title="提现" :autoBack="true" :placeholder="true" :titleStyle="state.titleStyle" :height="40"
			bgColor="#fff">
		</u-navbar>
		<view class="teamCenter">
			<view class='jiage'>
				<view class="text">提现金额</view>
				<view class="jiaen">
					<input type="text" v-model="state.amount" @input="getInput" placeholder="请输入提现金额">
				</view>
			</view>
			<view class='dui'>
				<text>手续费</text>
				<text style="font-weight: 100;">￥{{state.fei}}</text>
			</view>
			<view class='dui'>
				<text>提现方式</text>
				<view class="inRight">
					<view class="imgen" @click="getQie(1)">
						<image :src="state.renCode==1?'../../static/icon_select2@2x.png':'../../static/icon_select@2x.png'" mode=""></image>
							微信
					</view>
					<view class="imgen" @click="getQie(2)">
						<image :src="state.renCode==2?'../../static/icon_select2@2x.png':'../../static/icon_select@2x.png'" mode=""></image>
							支付宝支付
					</view>
				</view>
				<!-- <input type="text" placeholder="请输入兑换码" v-model="duiId"> -->
			</view>
			<view class='dui'>
				<text>收款账号</text>
				<input type="text" placeholder="请输入收款账号" v-model="state.account">
			</view>
			<view class='dui'>
				<text>真实姓名</text>
				<input type="text" placeholder="请输入真实姓名" v-model="state.real_name">
			</view>
		</view>
		<view class="butLi" @click="getTi">
		    确认提交
		</view>
		
	</view>
</template>
<script setup>
	import {ref,reactive,} from 'vue';
	import sheep from '@/sheep';
	import {onLoad} from '@dcloudio/uni-app';
	const state = reactive({
		renCode:1,//支付方式
		amount:'',//价格
		account:'',//账号
		real_name:'',//真是姓名
		configSet:0,//手续费率
		fei:'',//手续费
		juList:[
			{
				id:1,
				name:'微信支付',
				img:'../../static/pay_icon_wei@2x.png'
			},
			{
				id:2,
				name:'支付宝支付',
				img:'../../static/pay_icon_zhi@2x.png'
			}
		],
		juid:1,
		juShow:false,
	});
	onLoad((options) => {
		getConfigSet()
	});
	// 切换提现方式
	function getQie(e){
		state.renCode=e
	}
	// 提现
	async function getTi(){
		if (state.amount<1) {
		  uni.showToast({
		    title: "提现金额不能小于1",
		    icon: "none",
		    duration: 1000,
		  })
		  return
		}
		if (isInteger(state.amount)) {
		    console.log("该数字是整数");
		} else {
		    console.log("该数字不是整数");
			uni.showToast({
				  title: "提现金额必须为整数",
				  icon: "none",
				  duration: 1000,
				})
				return
		}
		const {code,data,msg} = await sheep.$api.user.withdrawAdd({
			token:uni.getStorageSync('token'),
			amount:state.amount,
			acc_type:state.renCode,
			account:state.account,
			real_name:state.real_name,
			commission:state.fei,
			prop:state.configSet,
		})
		if (code == 1) {
		   uni.showToast({
		   	title: '提交成功',
		   	icon: "none",
		   	mask: true,
		   	duration: 2000
		   })
		   uni.navigateBack({
		   	delta:1,     
		   });
		}else{
			uni.showToast({
				title: msg,
				icon: "none",
				mask: true,
				duration: 2000
			})
		}
	}
	// 计算手续费
	function getInput(e){
		if (e.detail.value<1) {
		  uni.showToast({
		    title: "提现金额不能小于1",
		    icon: "none",
		    duration: 1000,
		  })
		  return
		}
		var value=e.detail.value
		if (isInteger(value)) {
		    console.log("该数字是整数");
		} else {
		    console.log("该数字不是整数");
			uni.showToast({
				  title: "提现金额必须为整数",
				  icon: "none",
				  duration: 1000,
				})
				return
		}
		// // var zheng=Number.isInteger(value)
		// export const isPositiveInteger = (value) => {
		//   return /(^[0-9]\d*$)/.test(value)
		//   console.log()
		// }

		// console.log(zheng,'zheng')
		// if(zheng==false){
		// 	uni.showToast({
		// 	  title: "提现金额必须为整数",
		// 	  icon: "none",
		// 	  duration: 1000,
		// 	})
		// 	return
		// }
			 
		
		// console.log(e.detail.value)
		
	
		var lv=state.configSet/100
		state.fei=value*lv
	}
	
	function isInteger(obj) {
	 return obj%1 === 0
	}
    // 提现手续费率
	async function getConfigSet() {
		const {code,data} = await sheep.$api.test.configSet({
			config:'withdraw'
		})
		if (code == 1) {
		   state.configSet=data
		    var value=0
		   if(state.amount!=''){
			   value=state.amount
		   }
		  
		   var lv=data/100
		   state.fei=value*lv
		}
	}
	function getLeft(){
		uni.navigateBack({
			delta:1,//返回层数，2则上上页
		})
	}
</script>
<style  lang="scss">
	.tan{
		width:100%;
		height:100vh;
		position: fixed;
	    top:0;
		left:0;
		background: rgba(0,0,0,0.4);
		.bgcen{
			width: 100%;
			height: 700rpx;
			background: #fff;
			position:absolute;
			bottom:0;
			border-radius: 16rpx 16rpx 0 0;
			// position: relative;
			.qian{
				width: 100%;
				margin: 50rpx auto;
				text-align: center;
				font-size:48rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				text{
					font-size: 28rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #333333;
				}
			}
			.xuan{
				width:calc(100% - 64rpx);
				margin: 20rpx auto;
				overflow:hidden;
			    
				.ones{
					width: 100%;
					line-height:80rpx;
					text-align:center;
					border-radius: 12rpx;
					margin: 20rpx 0;
					display:flex;
					align-items: center;
					justify-content:space-between;
					.lezhi{
						display:flex;
						align-items: center;
						image{
							 width: 48rpx;
							 height:48rpx;
							 margin-right:10rpx;
						}
					 }
					image{
						 width: 48rpx;
						 height:48rpx;
					}
				}
				.onesmo{
					width: 100%;
					line-height:80rpx;
					text-align:center;
					border-radius: 12rpx;
					margin: 20rpx 0;
				}
			}
			.buc{
				width:calc(100% - 64rpx);
				margin: 20rpx auto;
				font-size: 28rpx;
				color: #999999;
			}
			
			.juBao{
				width:calc(100% - 64rpx);
				margin:50rpx auto;
				background: #1BDDD0;
				color:#fff;
				border-radius: 54rpx;
				line-height: 92rpx;
				text-align: center;
			}
			.times{
				text-align: center;
				width: 100%;
				line-height: 80rpx;
				font-weight: bold;
				border-bottom: 1px solid #EFEFEF;
			}
			.cha{
				position: absolute;
				top:20rpx;
				right:20rpx;
				image{
					width: 40rpx;
					height:40rpx;
				}
			}
		}
	}
	page {
		height: 100%;
		width: 100%;
		background-color: #F5F5F5;
		.main {
			height: 100%;
			width: 100%;
			background-color: #F5F5F5;
		}
		.img{
		    width:calc(100% - 48rpx);
		    padding:24rpx;
		    background: #fff;
			margin: 20rpx 0; 
			text-align: center;
			image{
				width: 440rpx;
				height:280rpx;
				// text-align: right;
			}
		}
		.teamCenter{
			width:100%;
			margin: 24rpx auto;
			.jiage{
				width:calc(100% - 48rpx);
				padding:0 24rpx;
				
				background: #fff;
				border-bottom:1px solid #F5F5F5;
				.text{
					line-height:50rpx ;
					padding-top:24rpx;
					font-weight: bold;
					font-size: 28rpx;
				}
				.jiaen{
					padding:12rpx 0;
					font-size:48rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #333333;
					input{
						font-size: 48rpx;
						height: 50rpx ;
						line-height: 50rpx ;
					}
					uni-input{
						line-height: 102rpx ;
					}
					.uni-input-input{
						line-height: 102rpx ;
					}
					.uni-input-placeholder{
						color: #333;
					}
				}
			}
			.dui{
			    width:calc(100% - 48rpx);
			    padding:0 24rpx;
				line-height: 102rpx ;
			    background: #fff;
				// margin: 20rpx 0; 
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				justify-content: space-between;
				border-bottom:1px solid #F5F5F5;
				text{
					font-weight: bold;
					font-size: 28rpx;
				}
				input{
					text-align: right;
				}
				.inRight{
					display: flex;
					align-items: center;
					justify-content: space-between;
					line-height:48rpx;
					.imgen{
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-left:20rpx;
						image{
							width: 48rpx;
							height:48rpx;
							// display: block;
							// margin-top: 20rpx;
						}
					}
					
				}
			}
		}
		
		.butLi{
			width: calc(100% - 64rpx);
			margin:60rpx auto 0;
			position: fixed;
			bottom:40rpx;
			left:32rpx;
			background: #1BDDD0;
			font-size:32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 92rpx;
			text-align: center;
			border-radius: 54rpx;
		}
		.buc{
			width:calc(100% - 64rpx);
			margin: 20rpx auto;
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
		}
		.duiHuan{
			width: calc(100% - 64rpx);
			margin:2 0rpx auto;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #666666;
			line-height: 50rpx;
		}
   }
   
</style>
